package org.zpmis.api.http;

import org.springframework.validation.annotation.Validated;
import org.zpmis.api.business.ContractTemplateWebService;
import org.zpmis.common.base.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.zpmis.common.exception.BusinessException;
import org.zpmis.common.result.PlatformResult;
import org.zpmis.domain.contract.qo.AddContractTemplateQo;
import org.zpmis.domain.contract.qo.ChangeStatusQo;
import org.zpmis.domain.contract.qo.ContractTemplateListQo;
import org.zpmis.domain.contract.qo.EditContractTemplateQo;

import javax.annotation.Resource;

/**
* created with CodeGenerator
* description: 合同模版 控制类
* @author  Yang
* date: 2021-6-2
* time: 14:52:19
*/
@RestController
@RequestMapping("/contract/template")
@Slf4j
public class ContractTemplateController extends BaseController{

    @Resource
    private ContractTemplateWebService contractTemplateWebService;


    /**
     * 新增合同模版
     * @param addContractTemplateQo
     * @return
     */
    @PostMapping("/addContractTemplate")
    public PlatformResult addContractTemplate(@Validated @RequestBody AddContractTemplateQo addContractTemplateQo){
        try {
            contractTemplateWebService.addContractTemplate(addContractTemplateQo);
        } catch (BusinessException be) {
            log.error("[ContractTemplateController]---addContractTemplate--->BusinessException:",be);
            return PlatformResult.failure(be.getResultCode());
        } catch (Exception e) {
            log.error("[ContractTemplateController]---addContractTemplate--->BusinessException:",e);
            return PlatformResult.failure();
        }
        return PlatformResult.success();
    }

    /**
     * 修改合同模板
     * @param editContractTemplateQo
     * @return
     */
    @PostMapping("/editContractTemplate")
    public PlatformResult editContractTemplate(@Validated @RequestBody EditContractTemplateQo editContractTemplateQo){

        try {
            contractTemplateWebService.editContractTemplate(editContractTemplateQo);
        } catch (BusinessException be) {
            log.error("[ContractTemplateController]---editContractTemplate--->BusinessException:",be);
            return PlatformResult.failure(be.getResultCode());
        } catch (Exception e) {
            log.error("[ContractTemplateController]---editContractTemplate--->BusinessException:",e);
            return PlatformResult.failure();
        }
        return PlatformResult.success();
    }

    /**
     * 模版状态变更
     * @param changeStatusQo
     * @return
     */
    @PostMapping("/changeStatus")
    public PlatformResult changeStatus(@Validated @RequestBody ChangeStatusQo changeStatusQo){

        try {
            contractTemplateWebService.changeStatus(changeStatusQo);
        } catch (BusinessException be) {
            log.error("[ContractTemplateController]---changeStatus--->BusinessException:",be);
            return PlatformResult.failure(be.getResultCode());
        } catch (Exception e) {
            log.error("[ContractTemplateController]---changeStatus--->BusinessException:",e);
            return PlatformResult.failure();
        }
        return PlatformResult.success();
    }

    /**
     * 合同模版列表查询
     * @param contractTemplateListQo
     * @return
     */
    @PostMapping("/contractTemplateList")
    public PlatformResult contractTemplateList(@RequestBody ContractTemplateListQo contractTemplateListQo){
        try {
            return PlatformResult.success(contractTemplateWebService.contractTemplateList(contractTemplateListQo));
        } catch (BusinessException be) {
            log.error("[ContractTemplateController]---contractTemplateList--->BusinessException:",be);
            return PlatformResult.failure(be.getResultCode());
        } catch (Exception e) {
            log.error("[ContractTemplateController]---contractTemplateList--->BusinessException:",e);
            return PlatformResult.failure();
        }
    }
}
